package com.wanpinghui.supplier.user.company;

import android.content.Intent;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.TextView;

import com.wanpinghui.supplier.R;
import com.wanpinghui.supplier.common.BaseActivity;
import com.wanpinghui.supplier.widgets.TimeSelectorDialog;
import com.wanpinghui.supplier.widgets.TitlePanelLayoutUser;
import com.wanpinghui.wphlibrary.model.user.bean.CourseBean;
import com.yunshl.yunshllibrary.utils.TimeUtil;
import com.yunshl.yunshllibrary.view.YunShlEditText;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;

/**
 * Created by tg596 on 2018/1/25.
 */
@ContentView(R.layout.layout_activity_development_path)
public class DevelopmentPathActivity extends BaseActivity {

    @ViewInject(R.id.tpl_title)
    private TitlePanelLayoutUser tpl_title;

    @ViewInject(R.id.tv_registered_time)
    private TextView mTvRegisteredTime;

    @ViewInject(R.id.edt_content)
    private YunShlEditText edt_content;

    private TimeSelectorDialog dialog;

    private long course_date;

    @Override
    public String getName() {
        return null;
    }

    @Override
    public boolean isBar() {
        return false;
    }

    @Override
    public void initViews() {
        tpl_title.showRightText();
        tpl_title.setRightTextColor(ContextCompat.getColor(this,R.color.colorPrimaryBlue));
        tpl_title.setRightText("确认");

    }

    @Override
    public void bindEvents() {
        tpl_title.setOnClickRightTxt(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                CourseBean bean = new CourseBean();
                bean.setCourse_date(course_date/1000);
                bean.setCourse_content(edt_content.getTextString());
                Intent intent  = new Intent();
                intent.putExtra("bean",bean);
                setResult(RESULT_OK,intent);
                finish();

            }
        });
        tpl_title.setOnClickBacktrack(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        mTvRegisteredTime.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (dialog == null) {
                    dialog = new TimeSelectorDialog(DevelopmentPathActivity.this);
                    dialog.setBindClickListener(new TimeSelectorDialog.BindClickListener() {
                        @Override
                        public void selectTime(long startTime ) {
                            course_date = startTime;
                            if (startTime > System.currentTimeMillis()){
                                showWarningText("所选日期不能大于当前日期");
                            }else {
                                mTvRegisteredTime.setText(TimeUtil.format(startTime, "yyyy-MM-dd"));
                            }

                        }
                    });
                }
                dialog.setTime(mTvRegisteredTime.getText().toString());
                dialog.show();
            }
        });
    }

    @Override
    public void initData() {

    }
}
